package silent.jdbc;


import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author liutao
 * Date 2021/7/17 2:17 下午
 * Description:
 * Version: 1.0
 **/
public class hikari {

    public static void main(String[] args) {
        HikariConfig config = new HikariConfig();
        config.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false");
        config.setUsername("root");
        config.setPassword("123456");
        config.addDataSourceProperty("cachePrepStmts", "true");
        config.addDataSourceProperty("prepStmtCacheSize", "250");
        config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
        HikariDataSource ds = new HikariDataSource(config);
        Connection conn = null;
        Statement statement = null;
        ResultSet rs = null;
        try{
            //创建connection
            conn = ds.getConnection();
            statement = conn.createStatement();

            //执行sql
            rs = statement.executeQuery("select age from person limit 1");

            //取数据
            if (rs.next()){
                System.out.println(rs.getString("age"));
            }

            //关闭connection
            conn.close();
        }
        catch (SQLException e){
            e.printStackTrace();
        }


    }
}
